
import edu.auctionmart.Role
import edu.auctionmart.User
import edu.auctionmart.Requestmap

class BootStrap {
	
	def authenticateService

    def init = { servletContext ->
		
		def adminRole = new Role(authority: "ROLE_ADMIN", description: "administrator")
		def userRole = new Role(authority: "ROLE_USER", description: "user")
		def testUser = new User(username: "admin", userRealName: "administrator", enabled: true, passwd: authenticateService.encodePassword("test"), email: "auctionmart@maine.edu")
		
		new Requestmap(url: '/login/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
		new Requestmap(url: '/user/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
		new Requestmap(url: '/index/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
		new Requestmap(url: '/auction/**', configAttribute: 'IS_AUTHENTICATED_FULLY').save()
		new Requestmap(url: '/bid/**', configAttribute: 'IS_AUTHENTICATED_FULLY').save()
		new Requestmap(url: '/webservices/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
		
		adminRole.addToPeople(testUser)
		if (testUser.validate()) {
			testUser.save(flush: true)
		}
			
		adminRole.save()
		userRole.save()
    }
    def destroy = {
    }
}
